package org.springblade.modules.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.enums.ApproveStatusEnum;
import org.springblade.modules.admin.vo.PlanApproveVO;
import org.springblade.modules.admin.vo.TaskStatusVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.admin.vo.BusinessApproveVO;
import org.springblade.modules.admin.service.IBusinessApproveService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.List;

/**
 * 审批流程表 控制器
 *
 * @author zcc
 * @since 2021-12-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("sida-maintain-admin/businessapprove")
@Api(value = "审批流程表", tags = "审批流程表接口")
public class BusinessApproveController extends BladeController {

	private final IBusinessApproveService businessApproveService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入businessApprove")
	public R<Object> detail(@ApiParam(value = "审批流程id") @RequestParam(value = "approveId") Long approveId) {
		return R.data(businessApproveService.detail(approveId));
	}

	@GetMapping("/myApproveTotal")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "我审批的（数量统计）")
	public R<Integer> myApproveTotal() {
		Integer total = businessApproveService.myApproveTotal();
		return R.data(total);
	}

	/**
	 * 自定义分页 审批流程表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入businessApprove")
	public R<IPage<BusinessApproveVO>> page(BusinessApproveVO businessApprove, Query query) {
 		IPage<BusinessApproveVO> pages = businessApproveService.selectBusinessApprovePage(Condition.getPage(query), businessApprove);
		return R.data(pages);
	}

	/**
	 * 业务流程审批
	 */
	@PostMapping("/approve")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "业务流程审批")
	public R save(@Valid @RequestBody BusinessApproveVO BusinessApprove) {
		return R.status(businessApproveService.approve(BusinessApprove));
	}

	/**
	 * 获取审核状态
	 * @return
	 */
	@GetMapping("/status")
	public R<List<TaskStatusVO>> selectApproveStatus(){
		return R.data(ApproveStatusEnum.getTaskStatus());
	}

	@GetMapping("/malfunctionApproveStatistical")
	@ApiOperation(value = "报障审批统计")
	public R<PlanApproveVO> malfunctionApproveStatistical(@RequestParam Long userId) {
		return R.data(businessApproveService.malfunctionApproveStatistical(userId));
	}
}
